package study.java.jvm.controller.mem.heap;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import study.java.jvm.request.MemRequest;
import study.java.jvm.service.HeapService;
import study.kit.eggs.result.Result;
import study.kit.eggs.result.Results;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

@Slf4j
@RestController
@RequestMapping("/heap")
public class HeapController {

    @Autowired
    private HeapService heapService;

    /**
     * OOM
     */
    @RequestMapping("/oom")
    public Result oom(@RequestBody MemRequest request) {
        //
        List<HeapObject> objLt = new ArrayList<>();
        //
        IntStream.range(0, request.getNum()).forEach(e -> {
            objLt.add(new HeapObject());
        });

        return Results.ok();
    }

    /**
     * 内存
     */
    @RequestMapping("/increase")
    public Result increase() {

        return Results.ok();
    }


    /**
     * 年轻代
     */
    @RequestMapping("/youngGen")
    public Result youngGen() {
        return Results.ok();
    }

    /**
     * 老年代
     */
    @RequestMapping("/oldGen")
    public Result oldGen() {
        return Results.ok();
    }
}
